define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'club/index',
                    table: 'c_club',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                search:false,
                commonSearch: false,
                mobileResponsive: false, //是否自适应移动端
                columns: [
                    [
						{field: 'id', title: __('Id')},
						{field: 'name', title: __('Name')},
						{field: 'usernum', title: '人数'},
						{field: 'totalnum', title: '总开房'},
						{field: 'totalscore', title: '荣誉分'},
						{field: 'todayscore', title: '今日荣誉分'},
						{field: 'diamond', title: '剩余房卡'},
                        {field: 'operate', title: __('Operate'), table: table, formatter: function (value, row, index) {
                        	return '<a class="btn btn-xs btn-info" href="/club/user/index/ids/'+row.id+'">进入</a>&nbsp;&nbsp;'
                        	+'<a title="添加房卡" class="btn btn-xs btn-success btn-dialog" href="/club/club/add/ids/'+row.id+'"> 房卡补充</a>&nbsp;&nbsp;'
                        	+'<a class="btn btn-xs btn-primary" href="/club/diamond/index/ids/'+row.id+'">房卡补充记录</a>';
						},events: Table.api.events.operate}
                    ]
                ],
                onLoadSuccess: function (data) {
					$("#top_club").html(data.total+'/5');
					$("#mydiamond").html('我的房卡：'+data.diamond);
	            }
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});